<template>
  <div class="icons">
    <swiper :options="swiperOption" ref="mySwiper" @someSwiperEvent="callback">
      <swiper-slide v-for ="(item, index) in pages" :key="index">
        <div class="icon" v-for="icon in item" :key="icon.id">
          <div class="icon-img">
            <img class="icon-img-content" :src="icon.imgUrl">
          </div>
          <p class="icon-desc">{{icon.desc}}</p>
        </div>
      </swiper-slide>
      <div class="swiper-pagination" slot="pagination"></div>
    </swiper>
  </div>
</template>

<script>
export default {
  name: 'HomeIcons',
  props: {
    iconList: {
      type: [Array, Object, Number],
      default () {
        return [{'id': '0001', 'imgUrl': 'http://img1.qunarzz.com/piao/fusion/1611/54/ace00878a52d9702.png', 'desc': '景点门票'}]
      }
    }
  },
  data () {
    return {
      swiperOption: {
        pagination: '.swiper-pagination'
      }
    }
  },
  computed: {
    pages () {
      let pages = []
      this.iconList.forEach((item, index) => {
        let page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
          pages[page].push(item)
        } else {
          pages[page].push(item)
        }
      })
      return pages
    }
  },
  methods: {
    callback () {}
  }
}
</script>

<style lang="stylus" scoped>
  @import '~styles/varibles.styl'
  @import '~styles/mixins.styl'
  .icons >>> .swiper-container
    width: 100%
    height: 0
    padding-bottom: 50%
    .swiper-pagination-bullets
      bottom .05rem
      .swiper-pagination-bullet
        width: .1rem
        height: .1rem
  .icon
    position relative
    float: left
    width: 25%
    height 0
    padding-bottom: 22%
    .icon-img
      position absolute
      top: 0
      left: 0
      bottom .44rem
      right 0
      box-sizing border-box
      padding .06rem
      .icon-img-content
        display block
        padding-top .12rem
        height 100%
        margin 0 auto
    .icon-desc
      position absolute
      left 0
      right 0
      bottom 0
      height .44rem
      line-height .6rem
      text-align center
      color $darkTextColor
      ellipsis()
</style>
